#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef struct
{
	char ch;
	string code;
}character;

character tt[30]={'A',".-",'B',"-...",'C',"-.-.",'D',"-..",'E',".",'F',"..-.",'G',"--.",
				'H',"....",'I',"..",'J',".---",'K',"-.-",'L',".-..",'M',"--",'N',"-.",
				'O',"---",'P',".--.",'Q',"--.-",'R',".-.",'S',"...",'T',"-",
						  'U',"..-",'V',"...-" ,'W',".--",'X',"-..-",'Y',"-.--",'Z',"--..",
						  '_',"..--",',',".-.-",'.',"---.",'?',"----" }; // 0 - 29
/*
char in_str[120];
char mid_str[500];
char to_str[120];
char length[120];
char temp[10];
*/
string in_str, mid_str, to_str, temp;
vector<int> length;

int main()
{
	int n, i, len, j, icase=0;
	cin >> n;
	while (n-->0)
	{
		cin >> in_str;
		mid_str = to_str = "";		
		length.clear();
		len = in_str.size();
		for (i=0; i<len; ++i)
		{
			for (j=0; j<=29; ++j)
				if (in_str[i]==tt[j].ch)
					break;
			mid_str += tt[j].code;
//			length[i]=strlen(tt[j].code);
			length.push_back(tt[j].code.size());
		}
		int site=0;
		for (i=len-1; i>=0; --i)
		{
			len = length[i];
		//	strncpy(temp, mid_str+site, len);
			temp = string(&mid_str[site], &mid_str[site+len]);
			site += len;
			for (j=0; j<=29; j++)
				if (temp == tt[j].code)
					break;
			to_str = to_str + tt[j].ch;
		}
//		printf("%d: %s\n", ++icase, to_str+1);		
		cout << ++icase << ": " << to_str << endl;
		
	}


	return 0;
}
